

#import "FAMHomeExerciseViewController.h"
#import "FAMHomeExerciseCollectionViewCell.h"
#import "FAMHomeExerciseAddCollectionViewCell.h"
@interface FAMHomeExerciseViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *FAMBottomBackView;
@property (weak, nonatomic) IBOutlet UITextField *FAMSearchTextField;
@property (weak, nonatomic) IBOutlet UIButton *FAMFamiliarButton;
@property (weak, nonatomic) IBOutlet UIButton *FAMCollectButton;
@property (weak, nonatomic) IBOutlet UIButton *FAMCustomButton;
@property (weak, nonatomic) IBOutlet UICollectionView *FAMCollectionView;



@end

@implementation FAMHomeExerciseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self FAM_showUi];
}
- (void)FAM_showUi {
    self.title = @"Exercise";
    UIView *rightBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 44)];
    UIButton *iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    iconButton.frame = CGRectMake(0, 0, 44, 44);
    [iconButton addTarget:self action:@selector(FAM_rightBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [iconButton setImage:[UIImage imageNamed:@"home_exercise_sprot"] forState:UIControlStateNormal];
    [rightBarView addSubview:iconButton];
    UILabel *numberLabel = [[UILabel alloc]init];
    numberLabel.textColor = kWhiteColor;
    numberLabel.font = [UIFont systemFontOfSize:12];
    numberLabel.text = @"2";
    numberLabel.textAlignment = NSTextAlignmentCenter;
    numberLabel.backgroundColor = kCustom0xColor(0xFF5324, 1.0);
    numberLabel.layer.cornerRadius = 10;
    numberLabel.layer.masksToBounds = YES;
    numberLabel.clipsToBounds = YES;
    [rightBarView addSubview:numberLabel];
    numberLabel.sd_layout.topEqualToView(rightBarView).rightEqualToView(rightBarView).heightIs(20).widthIs(20);
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBarView];
    self.FAMBottomBackView.layer.shadowColor = kBlackColor.CGColor;
    self.FAMBottomBackView.layer.shadowOffset = CGSizeMake(2, -2);
    self.FAMBottomBackView.layer.shadowOpacity = 0.8;
    self.FAMBottomBackView.layer.shadowRadius = 3;
    self.FAMSearchTextField.leftViewMode = UITextFieldViewModeAlways;
    self.FAMSearchTextField.leftView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_search"]];
    [self.FAMCollectionView registerNib:[UINib nibWithNibName:@"FAMHomeExerciseCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
    [self.FAMCollectionView registerNib:[UINib nibWithNibName:@"FAMHomeExerciseAddCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"addCell"];
    self.FAMCollectionView.showsVerticalScrollIndicator = NO;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 9) {
        FAMHomeExerciseAddCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCell" forIndexPath:indexPath];
        return cell;
    }else{
        FAMHomeExerciseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
        return cell;
    }
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 9) {
        [self.navigationController pushViewController:[FAMHomeExerciseAddViewController new] animated:YES];
    }else{
        FAMHomeSportsView *homeSportsView = [[FAMHomeSportsView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [self.view addSubview:homeSportsView];
    }
    
}







- (void)FAM_rightBarButtonClick:(UIButton *)sender{
    
}
- (IBAction)FAM_familiarButtonClick:(UIButton *)sender {
    [self FAM_sender:sender buttonOne:self.FAMCollectButton buttonTwo:self.FAMCustomButton];
}
- (IBAction)FAM_collectButtonClick:(UIButton *)sender {
    [self FAM_sender:sender buttonOne:self.FAMFamiliarButton buttonTwo:self.FAMCustomButton];
}
- (IBAction)FAM_customButtonClick:(UIButton *)sender {
    [self FAM_sender:sender buttonOne:self.FAMFamiliarButton buttonTwo:self.FAMCollectButton];
}
- (void)FAM_sender:(UIButton *)sender buttonOne:(UIButton *)buttonOne buttonTwo:(UIButton *)buttonTwo{
    sender.backgroundColor = kCustom0xColor(0x191919, 1.0);
    [sender setTitleColor:kWhiteColor forState:UIControlStateNormal];
    buttonOne.backgroundColor = kClearColor;
    [buttonOne setTitleColor:kCustom0xColor(0x757575, 1.0) forState:UIControlStateNormal];
    buttonTwo.backgroundColor = kClearColor;
    [buttonTwo setTitleColor:kCustom0xColor(0x757575, 1.0) forState:UIControlStateNormal];
}

- (IBAction)FAM_sportsButtonClick:(UIButton *)sender {
    
}

@end
